var express = require('express');
var path = require('path');
const cors=require("cors");
const history = require('connect-history-api-fallback');
//引入bodyParser中间件
const bodyParser=require('body-parser');
/*引入路由模块*/
var user=require("./routes/user");
var index=require("./routes/index");
var about=require("./routes/about");
var service=require("./routes/service");
var news=require("./routes/news");
var app = express();
//使用body-parser中间件，将post请求的数据解析为对象
app.use( bodyParser.urlencoded({
  extended:false
}) );
//配置路径
app.use(cors({
  origin:['http://localhost:8080', 'http://127.0.0.1:8080'],
  credentials:true
}))
app.use(express.json());
/*使用路由器来管理路由*/
app.use("/user",user);
app.use("/index",index);
app.use("/about",about);
app.use("/service",service);
app.use("/news",news);
//设置监听接口
app.listen(5050);
//托管静态资源到public下
app.use(express.static('../pet/public'));

//导出app
module.exports = app;